<html>
<head><meta charset="utf-8"><title>impl Trait and union regions · t-compiler/wg-nll · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/index.html">t-compiler/wg-nll</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html">impl Trait and union regions</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="167389453"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167389453" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167389453">(Jun 05 2019 at 13:43)</a>:</h4>
<p>So <span class="user-mention" data-user-id="116083">@pnkfelix</span> (and others) I've been working on some extensions to the region solver to address some existing limitations of impl trait (these are particularly important for async await). (cc <span class="user-mention" data-user-id="127859">@Taylor Cramer</span>)</p>



<a name="167389487"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167389487" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167389487">(Jun 05 2019 at 13:44)</a>:</h4>
<p>This raises some interesting questions in the context of the NLL solver</p>



<a name="167389534"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167389534" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167389534">(Jun 05 2019 at 13:44)</a>:</h4>
<p>cc <span class="user-group-mention" data-user-group-id="491">@WG-nll</span></p>



<a name="167389537"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167389537" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167389537">(Jun 05 2019 at 13:44)</a>:</h4>
<p>I was debating about how to discuss them -- I can certainly outline some of it here</p>



<a name="167389546"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167389546" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167389546">(Jun 05 2019 at 13:44)</a>:</h4>
<p>but maybe it's worth doing a call or something</p>



<a name="167389562"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167389562" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167389562">(Jun 05 2019 at 13:44)</a>:</h4>
<p>as in general I feel like this is the <em>sort</em> of issue I would like to think about how to document etc (i.e., kind of a meta issue re: lang spec)</p>



<a name="167389572"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167389572" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167389572">(Jun 05 2019 at 13:44)</a>:</h4>
<p>anyway let me outline the thing I'm looking at real fast</p>



<a name="167389656"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167389656" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167389656">(Jun 05 2019 at 13:46)</a>:</h4>
<p>if you have impl trait today, we can get in this strange scenario:</p>
<div class="codehilite"><pre><span></span><span class="k">fn</span> <span class="nf">foo</span><span class="o">&lt;</span><span class="na">&#39;a</span><span class="p">,</span><span class="w"> </span><span class="na">&#39;b</span><span class="o">&gt;</span><span class="p">(..)</span><span class="w"> </span>-&gt; <span class="nc">impl</span><span class="w"> </span><span class="n">Trait</span><span class="o">&lt;</span><span class="na">&#39;a</span><span class="p">,</span><span class="w"> </span><span class="na">&#39;b</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">..</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</pre></div>


<p>Here, the inferred return type can reference <code>'a</code> and <code>'b</code> but not other regions. The problem is that we have no way to express a cosntraint like that in our region solver.</p>



<a name="167389735"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167389735" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167389735">(Jun 05 2019 at 13:46)</a>:</h4>
<p>The only sort of constraint our existing solvers know how to handle is <code>'r1: 'r2</code>, but this would be what I'm calling a <em>pick constraint</em>.</p>



<a name="167389745"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167389745" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167389745">(Jun 05 2019 at 13:46)</a>:</h4>
<p>I've been writing it:</p>
<div class="codehilite"><pre><span></span>pick &#39;r0 from [&#39;r1...&#39;rN]
</pre></div>



<a name="167389760"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167389760" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167389760">(Jun 05 2019 at 13:46)</a>:</h4>
<p>i.e., it is satisfied if <code>'r0 == 'r[i]</code> for some <code>i &gt; 0</code></p>



<a name="167389795"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167389795" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167389795">(Jun 05 2019 at 13:47)</a>:</h4>
<p>(In today's code, that impl Trait I gave above is an error because there is no "least region" we can use as a bound; I am basically lifting this restriction)</p>



<a name="167389916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167389916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167389916">(Jun 05 2019 at 13:48)</a>:</h4>
<p>(As a further aside, <span class="user-mention" data-user-id="127859">@Taylor Cramer</span> and I realized that the existing inference scheme here was already a bit strange in that sometimes it has "room" to pick from a few sets of regions that would be sufficient; this is <em>mostly</em> unobservable, but not entirely, because of auto-trait leakage; i.e., you can have something like <code>impl Send for Foo&lt;'static&gt;</code> which can then observe if the region inferencer chose <code>'static</code> or not)</p>



<a name="167389967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167389967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167389967">(Jun 05 2019 at 13:49)</a>:</h4>
<p>The extension I'm doing is fairly conservative: it basically ignores <code>pick</code> constraints unless there is exactly one least choice it can use. I can give a bit more details but it's not the question that I am pondering. :)</p>



<a name="167390049"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390049" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390049">(Jun 05 2019 at 13:50)</a>:</h4>
<p>The interesting case is this one:</p>
<div class="codehilite"><pre><span></span><span class="k">trait</span><span class="w"> </span><span class="n">Trait</span><span class="o">&lt;</span><span class="na">&#39;a</span><span class="p">,</span><span class="w"> </span><span class="na">&#39;b</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Trait</span><span class="o">&lt;</span><span class="na">&#39;_</span><span class="p">,</span><span class="w"> </span><span class="na">&#39;_</span><span class="o">&gt;</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">foo</span><span class="o">&lt;</span><span class="na">&#39;a</span><span class="p">,</span><span class="w"> </span><span class="na">&#39;b</span><span class="o">&gt;</span><span class="p">(</span><span class="n">x</span>: <span class="kp">&amp;</span><span class="na">&#39;a</span><span class="w"> </span><span class="kt">u32</span><span class="p">,</span><span class="w"> </span><span class="n">y</span>: <span class="kp">&amp;</span><span class="na">&#39;b</span><span class="w"> </span><span class="kt">u32</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">impl</span><span class="w"> </span><span class="n">Trait</span><span class="o">&lt;</span><span class="na">&#39;a</span><span class="p">,</span><span class="w"> </span><span class="na">&#39;b</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="n">condition</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<a name="167390153"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390153" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390153">(Jun 05 2019 at 13:50)</a>:</h4>
<p>If you look carefully here, you will see that the return type is <code>&amp;'c u32</code> for some region <code>'c</code> where <code>'a: 'c</code> and <code>'b: 'c</code>. You could imagine writing this region as <code>'a &amp; 'b</code> (an intersection), though I've been thinking of it as a union <code>'a | 'b</code> because that fits the polonius model of regions as "loan sets"</p>



<a name="167390177"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390177" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390177">(Jun 05 2019 at 13:51)</a>:</h4>
<p>you expect the compiler to infer that type there?</p>



<a name="167390195"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390195" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390195">(Jun 05 2019 at 13:51)</a>:</h4>
<p>where its possible that <code>'c</code> is ReEmpty ?</p>



<a name="167390197"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390197" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390197">(Jun 05 2019 at 13:51)</a>:</h4>
<p>Anyway, my lexical solver rejects this example, but I believe it would be sound to accept it, in the sense that the caller can only use <code>impl Trait&lt;'a, 'b&gt;</code> when both <code>'a</code> and <code>'b</code> are live</p>



<a name="167390215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390215">(Jun 05 2019 at 13:51)</a>:</h4>
<blockquote>
<p>where its possible that <code>'c</code> is ReEmpty ?</p>
</blockquote>
<p>that is not possible</p>



<a name="167390217"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390217" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390217">(Jun 05 2019 at 13:51)</a>:</h4>
<p>oh, hmm, you expect <code>'c</code> will always exist (and be non-trivial)</p>



<a name="167390270"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390270" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390270">(Jun 05 2019 at 13:52)</a>:</h4>
<p>it must be live at the return site, for example</p>



<a name="167390286"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390286" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390286">(Jun 05 2019 at 13:52)</a>:</h4>
<p>the lexical solver probably can't accept this example ever</p>



<a name="167390291"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390291" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390291">(Jun 05 2019 at 13:52)</a>:</h4>
<p>because it can't really express what is needed</p>



<a name="167390303"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390303" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390303">(Jun 05 2019 at 13:52)</a>:</h4>
<p>it assigns the result the lifetime of the "Call site" (the outermost scope)</p>



<a name="167390332"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390332" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390332">(Jun 05 2019 at 13:52)</a>:</h4>
<p>actually i'm not sure if the NLL solver can easily do so either, now that I think about it</p>



<a name="167390339"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390339" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390339">(Jun 05 2019 at 13:52)</a>:</h4>
<p>(I think polonius could)</p>



<a name="167390370"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390370" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390370">(Jun 05 2019 at 13:53)</a>:</h4>
<p>I was thinking about how the NLL solver represents regions as a union of elements, where some of those elements can be "free regions" (like <code>'a</code> and <code>'b</code>)</p>



<a name="167390467"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390467" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390467">(Jun 05 2019 at 13:54)</a>:</h4>
<p>but that's actually not what we need here, as I noted above, you need the <em>intersection</em> (in NLL terms)</p>



<a name="167390476"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390476" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390476">(Jun 05 2019 at 13:54)</a>:</h4>
<p>right</p>



<a name="167390478"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390478" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390478">(Jun 05 2019 at 13:54)</a>:</h4>
<blockquote>
<p>(I think polonius could)</p>
</blockquote>
<p>but I haven't thought about this much and don't care to (yet)</p>



<a name="167390481"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390481" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390481">(Jun 05 2019 at 13:54)</a>:</h4>
<p>ok so maybe there's not so much of a question :)</p>



<a name="167390487"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390487" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390487">(Jun 05 2019 at 13:54)</a>:</h4>
<p>so maybe the representation could/should be a sum-of-products</p>



<a name="167390498"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390498" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390498">(Jun 05 2019 at 13:54)</a>:</h4>
<p>or rather, union-of-intersections  (in NLL terms) ?</p>



<a name="167390518"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390518" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390518">(Jun 05 2019 at 13:55)</a>:</h4>
<p>the reason I think polonius could handle this is that it is about tracking the <em>origins</em>, and basically you could imagine it saying something like "The origins of all regions in the hidden type cannot exceed a|b"</p>



<a name="167390531"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390531" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390531">(Jun 05 2019 at 13:55)</a>:</h4>
<p>which is what we want</p>



<a name="167390533"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390533" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390533">(Jun 05 2019 at 13:55)</a>:</h4>
<p>or is that not going to have the right properties, in terms of <del>lattices</del> glb's or whatnot</p>



<a name="167390551"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390551" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390551">(Jun 05 2019 at 13:55)</a>:</h4>
<p>anyway I don't know that this example is very important</p>



<a name="167390561"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390561" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390561">(Jun 05 2019 at 13:55)</a>:</h4>
<p>I just found it interesting as I was writing test cases</p>



<a name="167390575"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390575" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390575">(Jun 05 2019 at 13:55)</a>:</h4>
<blockquote>
<p>so maybe the representation could/should be a sum-of-products</p>
</blockquote>
<p>plausibly but I'm not inclined to do that without stronger motivation :)</p>



<a name="167390644"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390644" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390644">(Jun 05 2019 at 13:56)</a>:</h4>
<p>that code is pretty perf sensitive, among other things</p>



<a name="167390651"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390651" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390651">(Jun 05 2019 at 13:56)</a>:</h4>
<blockquote>
<p>anyway I don't know that this example is very important</p>
</blockquote>
<p>can it arise meaningfully when you don't have such a wide blanket impl?</p>



<a name="167390659"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390659" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390659">(Jun 05 2019 at 13:56)</a>:</h4>
<p>I'm not sure</p>



<a name="167390665"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390665" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390665">(Jun 05 2019 at 13:56)</a>:</h4>
<p>e.g. something that actually uses the region parameters</p>



<a name="167390674"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390674" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390674">(Jun 05 2019 at 13:56)</a>:</h4>
<p>it's also a pure extension</p>



<a name="167390692"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390692" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390692">(Jun 05 2019 at 13:56)</a>:</h4>
<p>i.e., we can do the thing I'm doing now, and see if people come up with good examples :)</p>



<a name="167390722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390722">(Jun 05 2019 at 13:57)</a>:</h4>
<p>good examples to motivate adding a more expressive system, you mean, right?</p>



<a name="167390723"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390723" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390723">(Jun 05 2019 at 13:57)</a>:</h4>
<p>regardless, even if we don't go in this direction, it still raises interesting questions about impl Trait -- the existing rules and support lack any sort of documentation to my knowledge</p>



<a name="167390731"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390731" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390731">(Jun 05 2019 at 13:57)</a>:</h4>
<blockquote>
<p>good examples to motivate adding a more expressive system, you mean, right?</p>
</blockquote>
<p>correct</p>



<a name="167390742"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390742" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390742">(Jun 05 2019 at 13:57)</a>:</h4>
<p>I would like to improve this situation (docs)</p>



<a name="167390751"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390751" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390751">(Jun 05 2019 at 13:57)</a>:</h4>
<p>I guess I should be working on an amendment to the reference or something</p>



<a name="167390755"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390755" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390755">(Jun 05 2019 at 13:57)</a>:</h4>
<blockquote>
<p>regardless, even if we don't go in this direction, it still raises interesting questions about impl Trait -- the existing rules and support lack any sort of documentation to my knowledge</p>
</blockquote>
<p>I think there's some amount of active confusion w.r.t. the interaction between impl Trait and lifetimes</p>



<a name="167390772"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390772" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390772">(Jun 05 2019 at 13:57)</a>:</h4>
<p>the rules are not very satisfying to me</p>



<a name="167390776"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390776" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390776">(Jun 05 2019 at 13:57)</a>:</h4>
<p>I was trying to find the dialogue I had with alexreg about the impl vs the spec on this front</p>



<a name="167390834"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390834" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390834">(Jun 05 2019 at 13:58)</a>:</h4>
<p>but I failed to find it quickly. I'll look again now</p>



<a name="167390843"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390843" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390843">(Jun 05 2019 at 13:58)</a>:</h4>
<p>I think the existing solution (you can reference lifetimes that appear in bounds) is ungreat</p>



<a name="167390867"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390867" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390867">(Jun 05 2019 at 13:58)</a>:</h4>
<p>or rather, it's a decent default, but I suspect we would do well to consider adding an explicit option</p>



<a name="167390879"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390879" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390879">(Jun 05 2019 at 13:58)</a>:</h4>
<p>but that's <em>kind of</em> a separate story (only kind of)</p>



<a name="167390902"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390902" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390902">(Jun 05 2019 at 13:59)</a>:</h4>
<p>(this is the issue I was thinking of : <a href="https://github.com/rust-lang/rust/issues/54184" target="_blank" title="https://github.com/rust-lang/rust/issues/54184">#54184</a> )</p>



<a name="167390922"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390922" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390922">(Jun 05 2019 at 13:59)</a>:</h4>
<p>what is the explicit option you are thinking of?</p>



<a name="167390935"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167390935" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167390935">(Jun 05 2019 at 13:59)</a>:</h4>
<p>namely there are two directions , or maybe three, that I could imagine you going in...</p>



<a name="167391039"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167391039" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167391039">(Jun 05 2019 at 14:00)</a>:</h4>
<p>we had discussed things like <code>impl&lt;'a&gt; Debug</code></p>



<a name="167391055"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167391055" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167391055">(Jun 05 2019 at 14:00)</a>:</h4>
<p>strongly related to <a href="https://github.com/rust-lang/rust/issues/54184" target="_blank" title="https://github.com/rust-lang/rust/issues/54184">#54184</a></p>



<a name="167391063"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167391063" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167391063">(Jun 05 2019 at 14:00)</a>:</h4>
<p>it would basically desugar to a "unused" type parameter"</p>



<a name="167391099"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167391099" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167391099">(Jun 05 2019 at 14:01)</a>:</h4>
<p>Okay. So a way to add lifetimes that can be referenced by the impl Trait even if they do not (and perhaps cannot) appear in the Trait signature itself, right?</p>



<a name="167391243"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167391243" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167391243">(Jun 05 2019 at 14:02)</a>:</h4>
<p>hmm somehow I never noticed PR <a href="https://github.com/rust-lang/rust/issues/57896" target="_blank" title="https://github.com/rust-lang/rust/issues/57896">#57896</a></p>



<a name="167392009"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167392009" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167392009">(Jun 05 2019 at 14:10)</a>:</h4>
<blockquote>
<p>Okay. So a way to add lifetimes that can be referenced by the impl Trait even if they do not (and perhaps cannot) appear in the Trait signature itself, right?</p>
</blockquote>
<p>yes. You can then imagine <code>impl Trait</code> as a default. The problem with this is the usual problem with defaults -- when you write <code>impl&lt;'a&gt;</code>, does that <em>add</em> to the default set?</p>



<a name="167392018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167392018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167392018">(Jun 05 2019 at 14:10)</a>:</h4>
<p>Or does it "reset" the default set?</p>



<a name="167392034"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167392034" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167392034">(Jun 05 2019 at 14:10)</a>:</h4>
<p>In particular, we default to capturing all type parameters -- what if you didn't want to?</p>



<a name="167392056"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167392056" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167392056">(Jun 05 2019 at 14:11)</a>:</h4>
<p>I'd say we should have a (different) way to mark lifetimes in the signature as not intended to be captured.</p>



<a name="167392066"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167392066" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167392066">(Jun 05 2019 at 14:11)</a>:</h4>
<p>the expectation I think was that you would use an explicit <code>abstract type</code> (or <code>type Foo = impl Trait</code>, whatever) for this case</p>



<a name="167392079"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167392079" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167392079">(Jun 05 2019 at 14:11)</a>:</h4>
<p>(which maybe is fine)</p>



<a name="167392090"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167392090" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167392090">(Jun 05 2019 at 14:11)</a>:</h4>
<p>but I think is a big jump</p>



<a name="167392111"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167392111" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167392111">(Jun 05 2019 at 14:11)</a>:</h4>
<p>I guess it depends how often</p>



<a name="167392117"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167392117" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167392117">(Jun 05 2019 at 14:11)</a>:</h4>
<p>this comes up a lot in the compiler</p>



<a name="167392140"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167392140" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167392140">(Jun 05 2019 at 14:11)</a>:</h4>
<p>often you want something like <code>fn foo&lt;'tcx, 'gcx&gt;() -&gt; impl Iterator&lt;Item = Ty&lt;'tcx&gt;&gt;</code> that wants to capture <code>'gcx</code></p>



<a name="167392142"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167392142" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167392142">(Jun 05 2019 at 14:11)</a>:</h4>
<p>anyway</p>



<a name="167405184"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167405184" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167405184">(Jun 05 2019 at 16:19)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> isn't this <a href="https://github.com/rust-lang/rust/issues/60670" target="_blank" title="https://github.com/rust-lang/rust/issues/60670">https://github.com/rust-lang/rust/issues/60670</a> ?</p>



<a name="167405202"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167405202" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167405202">(Jun 05 2019 at 16:19)</a>:</h4>
<p>Related</p>



<a name="167405287"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167405287" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167405287">(Jun 05 2019 at 16:20)</a>:</h4>
<p>Something like an existential lifetime is one way to solve it; <code>impl&lt;'gcx&gt;</code> is another.</p>



<a name="167405511"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167405511" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167405511">(Jun 05 2019 at 16:22)</a>:</h4>
<p>Notably we could say:</p>
<div class="codehilite"><pre><span></span><span class="k">fn</span> <span class="nf">foo</span><span class="o">&lt;</span><span class="na">&#39;a</span><span class="p">,</span><span class="w"> </span><span class="na">&#39;b</span><span class="o">&gt;</span><span class="p">(</span><span class="n">x</span>: <span class="kp">&amp;</span><span class="na">&#39;a</span><span class="w"> </span><span class="kt">u32</span><span class="p">,</span><span class="w"> </span><span class="n">y</span>: <span class="kp">&amp;</span><span class="na">&#39;b</span><span class="w"> </span><span class="kt">u32</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">impl</span><span class="w"> </span><span class="n">exists</span><span class="o">&lt;</span><span class="na">&#39;c</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">where</span><span class="w"> </span><span class="na">&#39;a</span>: <span class="na">&#39;c</span><span class="p">,</span><span class="w"> </span><span class="na">&#39;b</span>: <span class="na">&#39;c</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="n">Trait</span><span class="o">&lt;</span><span class="na">&#39;c</span><span class="p">,</span><span class="w"> </span><span class="na">&#39;c</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="n">condition</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<a name="167506048"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/impl%20Trait%20and%20union%20regions/near/167506048" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/impl.20Trait.20and.20union.20regions.html#167506048">(Jun 06 2019 at 18:05)</a>:</h4>
<p>plausible but not really the intended existential plan, which was more to make the <em>type</em> be <code>exists&lt;'c&gt; { ... }</code></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>